package com.example.leavemanagement.model.enums;

import com.example.leavemanagement.exception.BusinessException;
import com.example.leavemanagement.exception.ErrorCode;
import com.example.leavemanagement.exception.ThrowUtils;
import lombok.Getter;

import java.util.Arrays;
import java.util.Map;
import java.util.Objects;
import java.util.stream.Collectors;

/**
 * 图片审核
 * @author 炼金术士
 */
@Getter
public enum LeaveReviewStatusEnum {
    /**
     * 待审核
     */
    PENDING_REVIEW("待审核", 0),
    /**
     * 审核通过
     */
    REVIEW_PASSED("审核通过", 1),
    /**
     * 审核不通过
     */
    REVIEW_NOT_PASSED("审核不通过", 2);

    private static final Map<Integer, LeaveReviewStatusEnum> LEAVE_REVIEW_STATUS_ENUM_MAP =
            Arrays.stream(LeaveReviewStatusEnum.values())
                    .collect(Collectors.toMap(LeaveReviewStatusEnum::getValue, e -> e));

    private final String text;
    private final int value;

    LeaveReviewStatusEnum(String text, int value) {
        this.text = text;
        this.value = value;
    }

    /**
     * 根据value获取枚举
     */
    public static LeaveReviewStatusEnum getEnumByValue(Integer value) {
        LeaveReviewStatusEnum pictureReviewStatusEnum=value==null?null : LEAVE_REVIEW_STATUS_ENUM_MAP.getOrDefault(value, null);
        ThrowUtils.throwIf(Objects.isNull(pictureReviewStatusEnum), new BusinessException(ErrorCode.PARAMS_ERROR));
        return pictureReviewStatusEnum;
    }
}

